﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

namespace TSUILayer.Views.Reports
{
    public partial class SampleReportViewer : Form
    {
        public SampleReportViewer()
        {
            InitializeComponent();

        }

        private void SampleReportViewer_Load(object sender, EventArgs e)
        {

            RenderReportViewer(string.Empty,string.Empty);
            
        }
        public  void RenderReportViewer(string Parameters,string reportName)
        {
            try
            {
                string ReportServerUrl = System.Configuration.ConfigurationManager.AppSettings["ReportServerUrl"];
                string ReportPath = System.Configuration.ConfigurationManager.AppSettings["ReportFolderPath"];
                string ReportUserID = System.Configuration.ConfigurationManager.AppSettings["ReportUserID"];
                string ReportPwd = System.Configuration.ConfigurationManager.AppSettings["ReportPwd"];
                string ReportDomain = System.Configuration.ConfigurationManager.AppSettings["ReportDomain"];

                reportViewer1.ProcessingMode = ProcessingMode.Remote;
                //reportViewer1.ServerReport.ReportServerCredentials.NetworkCredentials =
                //    new CustomReportCredentials(ReportUserID, ReportPwd, ReportDomain).NetworkCredentials;
               ReportParameter param ;
                reportViewer1.ServerReport.ReportServerUrl = new Uri(@ReportServerUrl);
                if (reportName == "SpareInvoice")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SpareSalesInvoiceReport";
                    param = new ReportParameter("INVOICE_ID", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "TractorSale")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SalesInvoiceReport";
                    param = new ReportParameter("INVOICE_ID", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "DC")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/DeliveryChallanReport";
                    param = new ReportParameter("DC_NO", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "SpareStockReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SpareStockReport";
                                
                }
                else if (reportName == "CustomerDetailsReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/CustomerHistroyReport";
                    param = new ReportParameter("VILLAGE_ID", "0");
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "TractorStockReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/TractorStockReport";
                    //param = new ReportParameter("VILLAGE_ID", Convert.ToInt16("0"));
                    //reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "SpareScarcityReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SpareScarcityReport";
                    //param = new ReportParameter("VILLAGE_ID", Convert.ToInt16("0"));
                    //reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "TractorSalesReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/TractorSalesReport";
                    param = new ReportParameter("FROM_DATE", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "SpareSalesReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SpareSalesReport";
                    param = new ReportParameter("FROM_DATE", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "TractorPurchaseReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/TractorPurchaseReport";
                    param = new ReportParameter("FROM_DATE", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
                else if (reportName == "SparePurchaseReport")
                {
                    reportViewer1.ServerReport.ReportPath = "/" + ReportPath + "/SparePurchaseReport";
                    param = new ReportParameter("FROM_DATE", Parameters);
                    reportViewer1.ServerReport.SetParameters(param);
                }
             
               
                reportViewer1.RefreshReport();
            }
            catch (Exception ex)
            {


            }
        }
    }
}
